
/**
 * 对微信Api Promise化的公共函数
 */
export const wxapi = (wxApiName, obj) => {
  return new Promise((resolve, reject) => {
    wx[wxApiName]({
      ...obj,     //注意这里涉及的语法
      success: (res: any) => {
        resolve(res);
      },
      fail: (res) => {
        reject(res);
      }
    });
  });
},

/**
 * 以下是微信Api Promise化的特殊案例
 */
export const wxsetData = (pageObj, obj) => {
  if (pageObj && obj) {
    return new Promise((resolve, reject) => {
      pageObj.setData(obj, resolve(obj));
    });
  }
}

export default { wxapi, wxsetData }
